// 这里对本地存储作进一步封装，方便后续修改
const storage = window.localStorage

// 存
const setStorage = (key, value) => {
  if (value && typeof value === 'object') {
    value = JSON.stringify(value)
  }
  storage.setItem(key, value)
}

// 取
const getStorage = (key) => {
  try {
    return JSON.parse(storage.getItem(key))
  } catch (e) {
    return storage.getItem(key)
  }
}

// 删
const removeStorage = (key) => {
  storage.removeItem(key)
}

export {
  setStorage,
  getStorage,
  removeStorage
}
